package com.kkb.merchant.center.controller;


import com.kkb.merchant.center.api.TestService;
import com.kkb.merchant.center.common.exception.DefinitionException;
import com.kkb.merchant.center.common.pojo.UserInfo;
import com.kkb.merchant.center.common.util.HttpResult;
import com.kkb.merchant.center.common.util.ResultEnum;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Reference
    private TestService testService;

    @GetMapping("/helloWorld")
    public String getMessage(){
        return "hello world";
    }

    @GetMapping("/getlog")
    public String getLog(){
        return testService.getLog();
    }

    @GetMapping("/getError")
    public HttpResult getError(){
        HttpResult result = new HttpResult();
        int i = 10/0;
        return result;
    }


    @GetMapping("/getNullException")
    public HttpResult getNullException(){
        HttpResult result = new HttpResult();
        UserInfo userInfo = null;
        userInfo.getDescription();
        return result;
    }

    @GetMapping("/getDeException")
    public HttpResult<Object> DeExcpetion(){
        throw  new DefinitionException(400,"我犯错了");
    }

    @GetMapping("/getDeException2")
    public HttpResult<Object> DeExcpetion2(){
        throw  new DefinitionException(ResultEnum.NOT_PARAM);
    }
}
